<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="主题ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="topicId">
              <a-input-number v-model="model.topicId" placeholder="请输入主题ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="组ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groupInfo">
              <a-input v-model="model.groupInfo" placeholder="请输入组ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内容类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contentType">
              <a-input v-model="model.contentType" placeholder="请输入内容类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发布者信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="talkOwner">
              <a-input v-model="model.talkOwner" placeholder="请输入发布者信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="文本内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="talkText">
              <a-textarea v-model="model.talkText" rows="4" placeholder="请输入文本内容" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="talkImages">
              <a-input v-model="model.talkImages" placeholder="请输入图片内容"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最新点赞数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latestLikes">
              <a-input v-model="model.latestLikes" placeholder="请输入最新点赞数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="显示评论" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="showComments">
              <a-input v-model="model.showComments" placeholder="请输入显示评论"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="点赞数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="likesCount">
              <a-input-number v-model="model.likesCount" placeholder="请输入点赞数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="赞赏数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rewardsCount">
              <a-input-number v-model="model.rewardsCount" placeholder="请输入赞赏数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评论数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="commentsCount">
              <a-input-number v-model="model.commentsCount" placeholder="请输入评论数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否精华" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="digested">
              <a-input-number v-model="model.digested" placeholder="请输入是否精华" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否置顶" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sticky">
              <a-input-number v-model="model.sticky" placeholder="请输入是否置顶" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户特定信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userSpecific">
              <a-input v-model="model.userSpecific" placeholder="请输入用户特定信息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hashtags">
              <a-input v-model="model.hashtags" placeholder="请输入标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="uid">
              <a-input v-model="model.uid" placeholder="请输入用户ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="对象类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classname">
              <a-input v-model="model.classname" placeholder="请输入对象类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阅读数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="readingCount">
              <a-input-number v-model="model.readingCount" placeholder="请输入阅读数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阅读人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="readersCount">
              <a-input-number v-model="model.readersCount" placeholder="请输入阅读人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="附件列表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="talkFiles">
              <a-input v-model="model.talkFiles" placeholder="请输入附件列表"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CrawlHomePageQueryArticleForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           talkFiles: [
              { required: true, message: '请输入附件列表!'},
           ],
        },
        url: {
          add: "/crawlhomepagequeryarticle/crawlHomePageQueryArticle/add",
          edit: "/crawlhomepagequeryarticle/crawlHomePageQueryArticle/edit",
          queryById: "/crawlhomepagequeryarticle/crawlHomePageQueryArticle/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>